import random


class MyHangman:
    """Hangman game"""


    def __init__(self, word_list) -> None:
        """
        init word to guess
        :type word_list: list
        """
        list_len = len(word_list)
        # INIT PARAMS
        self.list = word_list
        # word to guess
        self.word = word_list[random.randint(0, list_len - 1)]
        # letter board
        self.letter_board = ["_"] * len(self.word)
        self.remaining_letters = list(self.word)
        self.wrong_guesses = 0
        # hangman emoji

        self.stages = ["",  # stages len = 7
                  "________      ",  # wrong guess = 1
                  "|      |      ",  # wrong guess = 2
                  "|      0      ",  # wrong guess = 3
                  "|     /|\\     ",  # wrong guess = 4
                  "|     / \\     ",  # wrong guess = 5
                  "|"]  # wrong guess = 6 -- GAME OVER
        # win or not
        self.win = False
        print("\n\n------- WELCOME TO HANGMAN GAME -------")

    def start(self):
        """
        GAME START
        """
        # GAME LOOP
        while self.wrong_guesses < (len(self.stages) - 1):
            print("\n")
            guess = input("Guess a letter -> ")
            # RIGHT GUESS
            if guess in self.remaining_letters:
                print("right!")
                guess_index = self.remaining_letters.index(guess)
                self.letter_board[guess_index] = guess
                self.remaining_letters[guess_index] = '$'
            else:
                self.wrong_guesses += 1
                print("Wrong Guess {0}/{1}!".format(self.wrong_guesses, 6))

            # PRINT LETTER BOARD AND HANGMAN EMOJI
            print(" ".join(self.letter_board))
            print("\n".join(self.stages[0: self.wrong_guesses + 1]))

            # IF ALL GUESSED
            if "_" not in self.letter_board:
                print('\nYou win! The word was:')
                print(' '.join(self.letter_board))
                self.win = True
                break

        # FINAL RESULT
        if not self.win:
            print('\nYou lose! The word was {}'.format(self.word))


game = MyHangman(["china", "japan", "india", "korea", "syria"])
game.start()
